﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using BLL.A;
using Model.A;

public partial class ActiveProductTrace_ManageActiveProduct_ManageAPackage_APackageAdd : System.Web.UI.Page
{
    private APackageTest apt;

    public ActiveProductTrace_ManageActiveProduct_ManageAPackage_APackageAdd()
    {
        apt = new APackageTest();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string packageProductSN = this.TextBox1.Text.Trim();
        APackageTestInfo apti = apt.LoadEntity(packageProductSN);
        if (!string.IsNullOrEmpty(apti.PackageProductSN))
        {
            string str = "已经包装过的成品序列号，无法再次包装啦！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        }
        else
        {
            APackageTestInfo apti_new = new APackageTestInfo(packageProductSN, DateTime.Now, User.Identity.Name);
            try 
            {
                apt.Insert(apti_new);
                string str = "包装成功！";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
                this.TextBox1.Text = "";
                this.TextBox1.Focus();
            }
            catch
            {
                string str = "出现错误，请联系相关人员！";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
            }
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string packageProductSN = this.TextBox2.Text.Trim();
        APackageTestInfo apti = apt.LoadEntity(packageProductSN);
        IList<APackageTestInfo> list = new List<APackageTestInfo>();
        list.Add(apti);
        this.DetailsView1.DataSource = list;
        this.DetailsView1.DataBind();
    }
}
